package br.ufc.ck0017.semantic.model;

import java.util.HashMap;
import java.util.Map;

public class SemanticClass {
    private SemanticClass parent;
    private String name;

    private Map<String, SemanticVariable> fields;
    private Map<String, SemanticMethod> methods;

    public SemanticClass() {
        fields = new HashMap<>();
        methods = new HashMap<>();
    }

    public void setName(String name) {
        this.name = name;
    }

    public void setParent(SemanticClass parent) {
        this.parent = parent;
    }

    public void addField(String name, SemanticVariable field) {
        if (fields.containsKey(name)) {
            throw new IllegalArgumentException();
        }

        fields.put(name, field);
    }

    public void addMethod(String name, SemanticMethod semanticMethod) {
        if (methods.containsKey(name)) {
            throw new IllegalArgumentException();
        }

        semanticMethod.setName(name);

        methods.put(name, semanticMethod);
    }

    public String getName() {
        return name;
    }

    public SemanticClass getParent() {
        return parent;
    }

    public SemanticVariable getField(String name) {
        return fields.get(name);
    }

    public SemanticMethod getMethod(String name) {
        return methods.get(name);
    }

    @Override
    public String toString() {
        return "SemanticClass{" +
                "parent=" + parent +
                ", name='" + name + '\'' +
                ", fields=" + fields +
                ", methods=" + methods +
                '}';
    }
}
